<?php
include ('config.php'); //file contain the database establish information
$currentConfID = '$_SESSION ["conference_id"]'; // need to actovate session

function sendRequest($requestUserID, $request, $conference_id)// I will take them from the session that has been chosen in the checklist
   {
    Session_start();
    $email = 'marouchiha@gmail.com'; //for testing the code
    $email = '$_SESSION["email"]'; // need to activate the session
    $currentConfID = '$_SESSION ["conference_id"]'; // need to actovate session

    include ('config.php'); //file contain the database establish information
    $i=0; //set counter by zero
	$request= $_POST['invitation']; //set request value by submit invitation
    while($row['member_id2']){ 
    $currentUserID = mysqli_query ($check, "SELECT member_id FROM Member WHERE email='".$email."'") //select the id from table member when the email enterd is the same as the email in the database to be get the id for the current user
    or die (mysql_error()); //returns the error description of the last MySQL operation
    $row = mysqli_fetch_assoc ($currentUserID); //return value of current user in an array from the querey if it is true
    $currentUserID =$row['member_id']; //set current user id to the id f=that we got from the querey
    $O = 'O';
    $getMembers = mysqli_query ($check, "SELECT member_id2 FROM member_request_member WHERE Approve IS NULL") or die (mysql_error()); //get the id of the second member which is the reciver from table member_request_member when the aproval is not accepted yet

    $requestUserID = $row[$i];
    mysqli_query($check, "UPDATE member_request_member SET request= $request where member_id2 = $row ['$currentUserID'] 
	and conference_id= $currentConfID and type = $O") // update table member_request_member that the request sent to be the rquest in database and member 2 will be current member
            or die(mysql_error());//returns the error description of the last MySQL operation
    $i++; 
    
    }
    $subject = 'Confo Request';
    $message= <<<EMAIL
The Confo site asks you to become a member in the review committe.
Please review this request in the requests section on your account for more details.

Thank you.
EMAIL;
            $from = 'info.confo@gmail.com';
            $headers = "From:" . $from;
            mail($getMembers, $subject, $message,$headers);
            
            // email form sent to member 2
   }
  
  if ( isset($_POST['send']) ) {
  sendRequest($row[$requestUserID],$_POST['invitation'], $currentConfID);
  }
  
  //if send button clicked the request will be sentwith request user ID and the invitation and the id of the conf that the organizer asked him to be organizer at it
?>

<html>
<head>
<title>Invite Reviewers</title>
</head>
<form method="post" action="sendToOrg.php">   
<textarea name="invitation" value ="" cols="80" rows="20">
Enter your invitation message here...
</textarea><br>
<tr><td><input type="submit" name="send" value="send"></td></tr>
<br>
</form>
</html>